package org.gp.Interfaz;

import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JDialog;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.SwingConstants;

import org.gp.tringes.GestorIGConsDatosPerro;
import org.gp.tringes.GestorIGGestionarPerros;
import org.gp.tringes.GestorIGInicio;


public class IGDatosPerro extends JDialog implements Observer {
	
	private String numPerro;
	
	private JPanel panel;
	private JPanel panel_1;
	private JPanel panel_2;
	private JLabel lblNumPerro;
	private JLabel lblNumPerro_1;
	private JLabel lblInvisible;
	private JLabel lblNombre;
	private JLabel lblNombre_1;
	private JButton btnModifNom;
	private JLabel lblRaza;
	private JLabel lblRaza_1;
	private JButton btnModifRaza;
	private JLabel lblSexo;
	private JLabel lblSexo_1;
	private JButton btnModifSexo;
	private JButton btnSalir;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					IGDatosPerro dialog = new IGDatosPerro("P001");
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);
					dialog.setModal(true);
					dialog.setResizable(false);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public IGDatosPerro(String pNumPerro) {
		numPerro = pNumPerro;
		GestorIGConsDatosPerro.getGestorIGConsDatosPerro().obtenerDatosPerro(numPerro);
		GestorIGGestionarPerros.getGestorIGGestionarPerros().addObserver(this);
		
		setBounds(100, 100, 500, 240);
		//ID-126
		setTitle(GestorIGInicio.getGestorIGInicio().getTexto(126));
		getContentPane().setLayout(new BorderLayout(0, 0));
		
		getContentPane().add(getPanel(), BorderLayout.NORTH);
		getContentPane().add(getPanel_1(), BorderLayout.CENTER);
		getContentPane().add(getPanel_2(), BorderLayout.SOUTH);
	}
	
	private JPanel getPanel(){
		if(panel == null){
			panel = new JPanel();
		}
		return panel;
	}
	
	private JPanel getPanel_1(){
		if(panel_1 == null){
			panel_1 = new JPanel();
			panel_1.setLayout(new GridLayout(0, 3, 0, 10));
			panel_1.add(getLblNumPerro());
			panel_1.add(getLblNumPerro_1());
			panel_1.add(getLblInvisible());
			panel_1.add(getLblNombre());
			panel_1.add(getLblNombre_1());
			panel_1.add(getBtnModifNom());
			panel_1.add(getLblRaza());
			panel_1.add(getLblRaza_1());
			panel_1.add(getBtnModifRaza());
			panel_1.add(getLblSexo());
			panel_1.add(getLblSexo_1());
			panel_1.add(getBtnModifSexo());
		}
		return panel_1;
	}
	private JLabel getLblNumPerro() {
		if (lblNumPerro == null) {
			//ID-127
			lblNumPerro = new JLabel(GestorIGInicio.getGestorIGInicio().getTexto(127));
			lblNumPerro.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblNumPerro;
	}
	private JLabel getLblNumPerro_1() {
		if (lblNumPerro_1 == null) {
			lblNumPerro_1 = new JLabel(GestorIGConsDatosPerro.getGestorIGConsDatosPerro().getNumPerro());
			lblNumPerro_1.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblNumPerro_1;
	}
	private JLabel getLblInvisible() {
		if (lblInvisible == null) {
			lblInvisible = new JLabel("");
		}
		return lblInvisible;
	}
	private JLabel getLblNombre() {
		if (lblNombre == null) {
			//ID-110
			lblNombre = new JLabel(GestorIGInicio.getGestorIGInicio().getTexto(110));
			lblNombre.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblNombre;
	}
	private JLabel getLblNombre_1() {
		if (lblNombre_1 == null) {
			lblNombre_1 = new JLabel(GestorIGConsDatosPerro.getGestorIGConsDatosPerro().getNombre());
			lblNombre_1.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblNombre_1;
	}
	private JButton getBtnModifNom() {
		if (btnModifNom == null) {
			//ID-111
			btnModifNom = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(111));
			btnModifNom.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					setVisible(false);
					JDialog cambiarNombre = new IGModifDatosPerro(lblNombre.getText(), numPerro);
					cambiarNombre.setResizable(false);
					cambiarNombre.setModal(true);
					cambiarNombre.setLocationRelativeTo(null);
					cambiarNombre.setVisible(true);
					setVisible(true);
				}
			});
		}
		return btnModifNom;
	}
	private JLabel getLblRaza() {
		if (lblRaza == null) {
			//ID-220
			lblRaza = new JLabel(GestorIGInicio.getGestorIGInicio().getTexto(220));
			lblRaza.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblRaza;
	}
	private JLabel getLblRaza_1() {
		if (lblRaza_1 == null) {
			lblRaza_1 = new JLabel(GestorIGConsDatosPerro.getGestorIGConsDatosPerro().getRaza());
			lblRaza_1.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblRaza_1;
	}
	private JButton getBtnModifRaza() {
		if (btnModifRaza == null) {
			//ID-128
			btnModifRaza = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(128));
			btnModifRaza.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setVisible(false);
					JDialog cambiarApel = new IGModifDatosPerro(lblRaza.getText(), numPerro);
					cambiarApel.setResizable(false);
					cambiarApel.setModal(true);
					cambiarApel.setLocationRelativeTo(null);
					cambiarApel.setVisible(true);
					setVisible(true);
				}
			});
		}
		return btnModifRaza;
	}
	private JLabel getLblSexo() {
		if (lblSexo == null) {
			//ID-221
			lblSexo = new JLabel(GestorIGInicio.getGestorIGInicio().getTexto(221));
			lblSexo.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblSexo;
	}
	private JLabel getLblSexo_1() {
		if (lblSexo_1 == null) {
			lblSexo_1 = new JLabel(GestorIGConsDatosPerro.getGestorIGConsDatosPerro().getSexo());
			lblSexo_1.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblSexo_1;
	}
	private JButton getBtnModifSexo() {
		if (btnModifSexo == null) {
			//ID-129
			btnModifSexo = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(129));
			btnModifSexo.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setVisible(false);
					JDialog cambiarContra = new IGModifDatosPerro(lblSexo.getText(), numPerro);
					cambiarContra.setResizable(false);
					cambiarContra.setModal(true);
					cambiarContra.setLocationRelativeTo(null);
					cambiarContra.setVisible(true);
					setVisible(true);
				}
			});
		}
		return btnModifSexo;
	}
	
	private JPanel getPanel_2(){
		if(panel_2 == null){
			panel_2 = new JPanel();
			panel_2.add(getBtnSalir());
		}
		return panel_2;
	}
	private JButton getBtnSalir() {
		if (btnSalir == null) {
			//ID-25
			btnSalir = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(25));
			btnSalir.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					dispose();
				}
			});
		}
		return btnSalir;
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
		GestorIGConsDatosPerro.getGestorIGConsDatosPerro().obtenerDatosPerro(numPerro);
		if((Boolean)arg.equals("Nombre") || (Boolean)arg.equals("Izena")){
			lblNombre_1.setText(GestorIGConsDatosPerro.getGestorIGConsDatosPerro().getNombre());
		}else{
			if((Boolean)arg.equals("Raza") || (Boolean)arg.equals("Arraza")){
				lblRaza_1.setText(GestorIGConsDatosPerro.getGestorIGConsDatosPerro().getRaza());
			}else{
				lblSexo_1.setText(GestorIGConsDatosPerro.getGestorIGConsDatosPerro().getSexo());
			}
		}
	}
}
